<template>
  <div></div>
</template>

<script>
import { mapState } from "vuex";
export default {
  components: {},
  data() {
    return {
      arr: [{ id: "", count: 0, key: this.$quinn.guid() }],
      formKey: this.$quinn.guid(),
      modify: "add",
      dialogVisible: false,
      row: {},
      form: {},
      ref: "form",
      labelWidth: "100px",
      inline: false,
      labelPosition: "top",
      fileList: [],
    };
  },
  computed: {
    ...mapState(["tokenv3"]),
    arrValues() {
      return this.arr
        .filter((e) => e.id && e.count)
        .map((e) => {
          return { id: e.id, count: e.count };
        });
    },
    dialogOpts() {
      const {
        dialogTitle = "",
        dialogTop: top = "8vh",
        title,
        dialogWidth: width = "500px",
      } = this;
      return {
        title: dialogTitle || title,
        "close-on-click-modal": false,
        width,
        top,
      };
    },
    formOpts() {
      const {
        form,
        formKey: key,
        ref,
        labelWidth,
        inline,
        labelPosition,
      } = this;
      return {
        form,
        key,
        ref,
        inline,
        labelWidth,
        labelPosition,
      };
    },
    formEvent() {
      return {
        submit: this.onSubmit,
      };
    },
    title() {
      return this.modify === "add" ? "新增" : "编辑";
    },
  },
  watch: {},
  methods: {
    onChange(res, k = "") {
      this["fileList" + k] = res;
    },
    getDirectoryItem() {
      const selectMap = this.$store.state.directoryMap;
      return Object.keys(selectMap).map((value) => ({
        value,
        label: selectMap[value],
      }));
    },
    onConfirm() {
      const form = this.$refs.form;
      form.submit();
    },
    submitDoneMsg() {
      this.$message.success("操作成功");
      this.arr = [{ id: "", count: 0, norms: "", key: this.$quinn.guid() }];
      this.submitDone();
    },
    submitDone() {
      this.dialogVisible = false;
      setTimeout(() => {
        this.$emit("change");
      }, 150);
    },
    showDialog(modify = "add", row = {}) {
      this.dialogVisible = true;
      this.row = row;
      this.modify = modify || "add";
      for (const key in this.form) {
        let defValue = "";
        if (Array.isArray(this.form[key].value)) defValue = [];
        if (Object.hasOwnProperty.call(row, key))
          this.form[key].value = row[key];
        else this.form[key].value = defValue;
      }
      this.formKey = this.$quinn.guid();
    },
  },
};
</script>

<style lang="less" scoped></style>
